# Maintainer: Saul Ibarra Corretge <saghul@gmail.com>

_realname=pyqt5
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}"
           "${MINGW_PACKAGE_PREFIX}-${_realname}-common")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}"
          "${MINGW_PACKAGE_PREFIX}-${_realname}-common")
pkgver=5.15.6
pkgrel=2
pkgdesc="Qt5 bindings for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('GPL')
url="https://riverbankcomputing.com/software/pyqt"
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-pyopengl"
         "${MINGW_PACKAGE_PREFIX}-python-ipykernel"
         "${MINGW_PACKAGE_PREFIX}-python-pygments"
         "${MINGW_PACKAGE_PREFIX}-python-qtpy"
         "${MINGW_PACKAGE_PREFIX}-pyqt5-sip"
         "${MINGW_PACKAGE_PREFIX}-qt5-base")
optdepends=("${MINGW_PACKAGE_PREFIX}-qt5-declarative"
            "${MINGW_PACKAGE_PREFIX}-qt5-activeqt"
            "${MINGW_PACKAGE_PREFIX}-qt5-connectivity"
            "${MINGW_PACKAGE_PREFIX}-qt5-location"
            "${MINGW_PACKAGE_PREFIX}-qt5-multimedia"
            "${MINGW_PACKAGE_PREFIX}-qt5-quick3d"
            "${MINGW_PACKAGE_PREFIX}-qt5-remoteobjects"
            "${MINGW_PACKAGE_PREFIX}-qt5-sensors"
            "${MINGW_PACKAGE_PREFIX}-qt5-serialport"
            "${MINGW_PACKAGE_PREFIX}-qt5-speech"
            "${MINGW_PACKAGE_PREFIX}-qt5-svg"
            "${MINGW_PACKAGE_PREFIX}-qt5-tools"
            "${MINGW_PACKAGE_PREFIX}-qt5-webchannel"
            "${MINGW_PACKAGE_PREFIX}-qt5-websockets"
            "${MINGW_PACKAGE_PREFIX}-qt5-winextras"
            "${MINGW_PACKAGE_PREFIX}-qt5-xmlpatterns"
            "${MINGW_PACKAGE_PREFIX}-qtwebkit")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-sip"
             "${MINGW_PACKAGE_PREFIX}-pyqt-builder"
             "${MINGW_PACKAGE_PREFIX}-python-packaging"
             "${MINGW_PACKAGE_PREFIX}-qt5-declarative"
             "${MINGW_PACKAGE_PREFIX}-qt5-activeqt"
             "${MINGW_PACKAGE_PREFIX}-qt5-connectivity"
             "${MINGW_PACKAGE_PREFIX}-qt5-location"
             "${MINGW_PACKAGE_PREFIX}-qt5-multimedia"
             "${MINGW_PACKAGE_PREFIX}-qt5-quick3d"
             "${MINGW_PACKAGE_PREFIX}-qt5-remoteobjects"
             "${MINGW_PACKAGE_PREFIX}-qt5-sensors"
             "${MINGW_PACKAGE_PREFIX}-qt5-serialport"
             "${MINGW_PACKAGE_PREFIX}-qt5-speech"
             "${MINGW_PACKAGE_PREFIX}-qt5-svg"
             "${MINGW_PACKAGE_PREFIX}-qt5-tools"
             "${MINGW_PACKAGE_PREFIX}-qt5-webchannel"
             "${MINGW_PACKAGE_PREFIX}-qt5-websockets"
             "${MINGW_PACKAGE_PREFIX}-qt5-winextras"
             "${MINGW_PACKAGE_PREFIX}-qt5-xmlpatterns"
             "${MINGW_PACKAGE_PREFIX}-qtwebkit")
options=('strip' 'staticlibs')
source=(https://pypi.python.org/packages/source/P/PyQt5/PyQt5-${pkgver}.tar.gz
        001-configure-fix.patch)
sha256sums=('80343bcab95ffba619f2ed2467fd828ffeb0a251ad7225be5fc06dcc333af452'
            'd68f49a58a410a6c802e016dfeb59585b7b994a63f4e94da52aebe01a8d5c28a')

prepare() {
  cd PyQt5-${pkgver}
  patch -p1 -i ${srcdir}/001-configure-fix.patch
}

build() {
  [[ -d python-build-${MSYSTEM} ]] && rm -rf python-build-${MSYSTEM}
  cp -r PyQt5-${pkgver} python-build-${MSYSTEM} && cd python-build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--api-dir=;" \
  ${MINGW_PREFIX}/bin/sip-build \
    --confirm-license \
    --link-full-dll \
    --no-make \
    --concatenate 2 \
    --api-dir=${MINGW_PREFIX}/share/qt5/qsci/api/python \
    --qmake=${MINGW_PREFIX}/bin/qmake.exe \
    --verbose

    cd build
    make V=1
}

package(){
  local _pysite=$(cygpath -u $(${MINGW_PREFIX}/bin/python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"))
  cd python-build-${MSYSTEM}/build
  # INSTALL_ROOT is needed for the QtDesigner module, the other Makefiles use DESTDIR
  MSYS2_ARG_CONV_EXCL="${_pysite}" \
  make DESTDIR="${pkgdir}" INSTALL_ROOT="${pkgdir}" install

  # compile Python bytecode
  ${MINGW_PREFIX}/bin/python -m compileall -d / "$pkgdir"${MINGW_PREFIX}/lib
  ${MINGW_PREFIX}/bin/python -O -m compileall -d / "$pkgdir"${MINGW_PREFIX}/lib
}
